package org.example.Servlet.TopicServlet;

import org.example.Dao.TopicDao;
import org.example.entity.TopAndOpt;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/admin/topic/editTopic")
public class EditTopicServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int tid = Integer.parseInt(req.getParameter("tid"));
        HttpSession session = req.getSession();
        TopicDao topicDao = new TopicDao();
        try {
            TopAndOpt topAndOpt = topicDao.getTopicAndOption(tid);
            session.setAttribute("topAndOpt", topAndOpt);
            resp.sendRedirect(req.getContextPath() + "/views/topic/edit.jsp");
        } catch (Exception e) {
            System.out.println("to edit topic error ==> " + e.getMessage());
            resp.sendRedirect(req.getContextPath() + "/views/admin/index.jsp");
        }


    }
}
